{{define "mirror"}}
{{template "top" .}}

<div class="card shadow-sm mb-3">
  <div class="card-header">
    {{if not .mirror.ID}}
      New Mirror
    {{else}}
      Update mirror {{.mirror.ID}}
    {{end}}
  </div>

  <div class="card-body">
    <form method="POST" action="/mirrors/{{.mirror.ID}}" class="m-0 p-0">
      <div class="row g-3">
        <div class="col-12">
          <div class="form-floating">
            <input type="text" name="index-file" id="index-file" value="{{.mirror.IndexFile}}" class="form-control" placeholder="Index File">
            <label for="index-file" class="form-label">Index File</label>
          </div>
          <div class="form-text text-muted">
            Full URL of the index file from which to read. Example: <code>https://mysever/exports/index.txt</code>.
          </div>
        </div>

        <div class="col-12">
          <div class="form-floating">
            <input type="text" name="export-root" id="export-root" value="{{.mirror.ExportRoot}}" class="form-control" placeholder="Export Root">
            <label for="export-root" class="form-label">Export Root</label>
          </div>
          <div class="form-text text-muted">
            Full URL to the export root. Example: <code>https://myserver/</code>.
          </div>
        </div>

        <div class="col-12">
          <div class="form-floating">
            <input type="text" name="cloud-storage-bucket" id="cloud-storage-bucket" value="{{.mirror.CloudStorageBucket}}" class="form-control" placeholder="Cloud Storage Bucket">
            <label for="cloud-storage-bucket" class="form-label">Cloud Storage Bucket</label>
          </div>
          <div class="form-text text-muted">
            Name of the destination storage bucket. Example: <code>my-bucket</code>.
          </div>
        </div>

        <div class="col-12">
          <div class="form-floating">
            <input type="text" name="filename-root" id="filename-root" value="{{.mirror.FilenameRoot}}" class="form-control" placeholder="Filename Root">
            <label for="filename-root" class="form-label">Filename Root</label>
          </div>
          <div class="form-text text-muted">
            Root where the new file should be written. Example: <code>/path/to/new</code>
          </div>
        </div>

        <div class="col-12">
          <div class="form-floating">
            <input type="text" name="filename-rewrite" id="filename-rewrite" value="{{.mirror.FilenameRewrite | deref}}" class="form-control" placeholder="Filename Rewrite">
            <label for="filename-rewrite" class="form-label">Filename Rewrite</label>
          </div>
          <div class="form-text text-muted">
            Optional regular expression for rewriting imports.
          </div>
        </div>

        <div class="col-12 d-grid">
          <button type="submit" class="btn btn-primary" name="action" value="save">Save changes</button>
        </div>

        {{if .mirror.ID}}
          <div class="col-12">
            <button type="submit" name="action" value="delete" class="btn btn-link btn-sm px-0 text-danger">Delete</button>
          </div>
        {{end}}
      </div>
    </form>
  </div>
</div>

{{if .mirror.ID}}
  <div class="card shadow-sm">
    <div class="card-header">Mirror Files</div>
    {{if .mirrorFiles}}
      <table class="table table-striped mb-0">
        <thead>
          <tr>
            <th scope="col">Filename</th>
            <th scope="col">Local Filename</th>
          </tr>
        </thead>
        <tbody>
          {{range .mirrorFiles}}
            <tr>
              <td class="font-monospace">{{.Filename}}</td>
              <td class="font-monospace">{{.LocalFilename}}</td>
            </tr>
          {{end}}
        </tbody>
      </table>
    {{else}}
      <div class="card-body">
        <div class="alert alert-warning mb-0" role="alert">
          There are currently no mirror files.
        </div>
      </div>
    {{end}}
  </div>
{{end}}

{{template "bottom" .}}
{{end}}
